import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsOptional, IsEmail } from 'class-validator';

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 100, default: '' })
  @ApiProperty({ description: '用户的昵称' })
  @IsNotEmpty({ message: '用户昵称不能为空' })
  nickname: string;

  @Column({ length: 100, unique: true })
  @ApiProperty({ description: '用户的账号' })
  @IsNotEmpty({ message: '密码不能为空' })
  username: string;

  @Column()
  @ApiProperty({ description: '用户的密码' })
  @IsNotEmpty({ message: '密码不能为空' })
  password: string;

  @Column({ default: '' })
  @ApiProperty({ description: '用户头像' })
  @IsNotEmpty({ message: '用户头像不能为空' })
  avatar: string;

  @Column({ default: '' })
  @ApiProperty({ description: '邮箱' })
  @IsOptional()
  @IsEmail({}, { message: '邮箱格式不正确' })
  email: string;

  @Column('simple-enum', {
    enum: ['root', 'author', 'visitor'],
    default: 'visitor',
  })
  @ApiProperty({ description: '用户角色' })
  @IsNotEmpty({ message: '用户角色不能为空' })
  role: string;

  @Column({
    name: 'create_time',
    type: 'timestamp',
    default: () => 'CURRENT_TIMESTAMP',
  })
  @ApiProperty({ description: '创建时间' })
  createTime: Date;

  // @Column({
  //   name: 'update_time',
  //   type: 'timestamp',
  //   default: () => 'CURRENT_TIMESTAMP',
  // })
  // @ApiProperty({ description: '更新时间' })
  // updateTime: Date;
  @UpdateDateColumn({ type: 'timestamp' })
  @ApiProperty({ description: '更新时间' })
  updateTime: Date;
}
